﻿@using System.Net.Http
@using System.Net.Http.Headers
@using System.Net.Http.Json
@using LaserMark.Extensions
@namespace LaserMark.Components

<div class="form-footer">
    <Button Text="生产" OnClick="@OnProduce" Icon="fa fa-save"></Button>
    <Button Text="关闭" OnClick="@OnClose" Icon="fa fa-close" Color="Color.Secondary"></Button>
</div>

@code {

    [Inject]
    [NotNull]
    private IHttpClientFactory? HttpClientFactory { get; set; }

    [Parameter]
    public List<Opts>? Value { get; set; }

    [Parameter]
    public EventCallback<List<Opts>> ValueChanged { get; set; }

    [CascadingParameter]
    [NotNull]
    public Func<Task>? CloseAsync { get; set; }

    [Parameter]
    public Func<string?, Task<bool>>? OnSave { get; set; }

    private async Task OnClose()
    {
        await CloseAsync();
    }

    private async Task OnProduce()
    {
        var client = HttpClientFactory.CreateClient();
        client.BaseAddress = new Uri("http://192.168.0.107:7000/");
        var mes = await client.PostAsJsonAsync($"/sales/optimaze/optProduceState", Value.Select(s => new { OptId = s.OptId, OptProduceState = 1 }));
        var aa = await mes.Content.ReadAsStringAsync();

        foreach (var v in Value)
        {
            var msg = await client.GetFromJsonAsync<ErpResponse<string>>($"/sales/optimaze/eventualNames/{v.OptId}");

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(msg.Msg)))
            {
                var cc = ConvertOriginalInfo.Convert(stream);
            }
        }
    }

}
